<template>

  <div>
    <el-button type="primary" @click="businessreview"><i class="el-icon-edit" />审核</el-button>
    <el-table
      :data="tableData"
      border
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        type="index"
        width="50"
      />
      <el-table-column
        type="selection"
        width="55"
      />
      <el-table-column
        prop="id"
        label="商户ID"
        width="180"
      />
      <el-table-column
        prop="name"
        label="商户名称"
        width="180"
      />
      <el-table-column
        prop="corporation"
        label="法人"
        width="180"
      />
      <el-table-column
        prop="address"
        label="地址"
        width="180"
      />
      <el-table-column
        prop="type"
        label="类型"
        width="180"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.type==1">公司化公寓</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="status"
        label="状态"
        width="180"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.status==1">审核通过</span>
          <span v-if="scope.row.status==2">审核不通过</span>
          <span v-if="scope.row.status==3">待审核</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="userE.username"
        label="管理员"
        width="180"
      />
      <el-table-column
        prop="createTime"
        label="申请时间"
        width="180"
        :formatter="changeDate"
      />
    </el-table>
    <el-pagination
      :page-sizes="[10, 20, 30, 40]"
      :page-size="page.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="page.total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>

</template>

<script>
export default {
  name: 'Business',
  data() {
    return {
      multipleSelection: [],
      tableData: [],
      page: {
        pageNo: 1,
        pageSize: 10,
        total: 0
      }
    }
  },
  mounted() {
    this.list()
  },
  methods: {
    changeDate(row, column) {
      const date = row[column.property]
      if (date == null) {
        return ''
      }
      return this.moment(date).format('YYYY-MM-DD HH:mm:ss')
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    businessreview() {
      if (this.multipleSelection.length > 1) {
        this.$message('只能选择一条记录')
      } else if (this.multipleSelection.length === 0) {
        this.$message('请选择一条记录')
      } else {
        this.$router.push({ name: 'Businessreview', params: { business: this.multipleSelection[0] }})
      }
    },
    handleSizeChange(val) {
      this.page.pageSize = val
      this.list()
    },
    handleCurrentChange(val) {
      this.page.pageNo = val
      this.list()
    },
    list() {
      this.axios.post('http://localhost:9999/wish/sizu/system/business/list', this.page).then((res) => {
        this.tableData = res.data.obj.list
        this.page.pageNo = res.data.obj.pageNum
        this.page.total = res.data.obj.total
      })
    }
  }
}
</script>

<style scoped>

</style>
